<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/htmlFormat.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #panel{width:90%;}
            #pageContent{width:98%; background:#FFF; border:1px solid #039; height:300px;font-size:13px;padding:3px;line-height:24px;font-family:Verdana, Geneva, sans-serif;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="frm" name="frm">
                <table>
                    <tr>
                        <th colspan="5">静态页面更新</th>
                    </tr>
                    <tr>
                        <td height="31" class="r">页面地址：</td>
                        <td colspan="2">
                            <input name="pageUrl" type="text" id="pageUrl" size="60"></td>
                        <td width="18%"><input type="button" name="btnReadPage" id="btnReadPage" value="读取页面" onclick="readPage();"></td>
                        <td>页面编码：
                            <select name="readCharset" id="readCharset">
                                <option value="utf-8">utf-8</option>
                                <option value="gbk">gbk</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td height="26" class="r">远端保存地址：</td>
                        <td colspan="2"><input name="postUrl" type="text" id="postUrl" size="60"></td>
                        <td>保存编码：
                            <select name="writeCharset" id="writeCharset">
                                <option value="utf-8">utf-8</option>
                                <option value="gbk">gbk</option>
                            </select></td>
                        <td>
                            <input type="button" name="btnClearWhiteChar" id="btnClearWhiteChar" value="清理空格回车" onClick="clearWhiteChar();">
                        </td>
                    </tr>
                    <tr>
                        <td height="26" class="r">本地保存路径：</td>
                        <td colspan="2"><input name="savePath" type="text" id="savePath" size="60"></td>
                        <td colspan="2">远端保存地址、本地保存路径必须填写其中一项。</td>
                    </tr>
                    <tr>
                        <td height="22" class="r">页面代码：</td>
                        <td colspan="2">&nbsp;</td>
                        <td colspan="2"><input type="button" name="btnFormat" id="btnFormat" value="格式化代码" onClick="formatHtml();">
                        <input type="button" name="btnAppendDate" id="btnAppendDate" value="加入时间戳" onClick="appendDate();">
                        <input type="button" name="btnClear" id="btnClear" value="清空" onClick="clearContent();">
                        </td>
                    </tr>
                    <tr>
                        <td height="148" colspan="5" class="r">
                            <textarea name="pageContent" id="pageContent" cols="160" rows="50"></textarea></td>
                    </tr>
                    <tr>
                        <td width="14%" align="right">&nbsp;</td>
                        <td width="10%">&nbsp;</td>
                        <td colspan="2"><input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="提交更改" onclick="savePageSet();" />      </td>
                        <td width="27%"><a href="javascript:adjustTextareaHeight(1);" style="font-size:16px;">[+]</a> <a href="javascript:adjustTextareaHeight(-1);" style="font-size:16px;">[-]</a></td>
                    </tr>
                </table>
            </form>
        </div>



        <script type="text/javascript">
            // 调整文本区高度
            function adjustTextareaHeight(k){
                var h = $('#pageContent').css('height');
                var _h = parseInt(h.substring(0, h.length-2));
                if(k>0){
                    $('#pageContent').css('height', ((_h+50).toString()+'px'));
                }else{
                    if( (_h - 50)<200){
                        return;
                    }
                    $('#pageContent').css('height', ((_h-50).toString()+'px'));
                }
            };
            // 格式化HTML
            function formatHtml(){
                var html = $('#pageContent').val() || '';
                $('#pageContent').val(getFormatHtml(html));
            };
            // 追加时间戳到代码末尾
            function appendDate(){
                var fmt = "yyyy-MM-dd HH:mm:ss";
                var t = '<!-- '+ (new Date()).Pattern(fmt) + ' -->';
                var html = $('#pageContent').val() || '';
                $('#pageContent').val(html + t);
            };
            // clear
            function clearContent(){
                $('#pageContent').val('');
            };
            // 清理空格和回车符
            function clearWhiteChar(){
                var html = $('#pageContent').val() || '';
                var pageHtml = html.replace(/[\s]{3}/g," ").replace(/[\s]{2}/g," ").replace(/>\s</g,"><").replace(/[\f\t\b\n\r]{1,}/g,"");
                $('#pageContent').val(pageHtml);
            };
            // 读取URL页面数据并填充到文本区域
            function readPage(){
                $('#btnReadPage').attr('disabled','disabled');
                var p={
                    pageUrl:$('#pageUrl').val(),
                    charset:$('#readCharset').val(),
                    t:ut.r()
                };
                $.get('../app/pageset/read_page.shtm',$.param(p),function(x){
                    $('#pageContent').val($.trim(x));
                    $('#btnReadPage').removeAttr('disabled');
                });
            };
            // 保存更改数据
            function savePageSet(){
                var p={
                    postUrl:$('#postUrl').val(),
                    savePath:$('#savePath').val(),
                    charset:$('#writeCharset').val(),
                    pageContent:$('#pageContent').val(),
                    t:ut.r()
                };
                if( ( va.isnull(p.postUrl) && va.isnull(p.savePath) ) || va.isnull(p.pageContent)){
                    ut.m('请检查提交表单参数.');
                    return;
                }
                if(!window.confirm("确定执行页面更新吗？执行后不可恢复.")){
                    return;
                }
                TxBox.wait('正在保存页面数据...');
                $('#submitBtn').attr('disabled','disabled');
                $.post('../app/pageset/save_page.shtm',$.param(p),function(x){
                    ut.m(x);
                    $('#submitBtn').removeAttr('disabled');
                    TxBox.hide();
                });
            };
        </script>
    </body>
</html>
